import { hasDeployContractList } from '@/api';
import { useState } from 'react';

export const useDeployContractList = () => {
  const [list, setList] = useState<any[]>([]);
  const [pageSize, setPageSize] = useState<number>(10);
  const [recordCount, setRecordCount] = useState<number>(0);
  const [pageIndex, setPageIndex] = useState<number>(1);

  const getDeployContractList = async (param:{
    pageSize?:number;
    page?:number;
  }) => {
    const res = await hasDeployContractList(param);
    if (res.data?.hasDeployList?.length) {
      setRecordCount(res.data?.total || 0);
      setList(res.data?.hasDeployList || []);
    }else{
      setRecordCount(0);
      setList([]);
    }
    if (param.page) {
      setPageIndex(param.page);
    }
    if (param.pageSize) {
      setPageSize(param.pageSize);
    }
  };
  return {
    pageIndex,
    pageSize,
    list,
    getDeployContractList,
    recordCount,
    setPageIndex,
    setPageSize,
    setRecordCount
  };
};
